/**
 * Filename: goods_detail.js
 * Author: xhh
 * Description: 商品详情页js文件
 * Date: 2018.04.02
 */
$(function () {
    // 设置克拉进度条
    var $silderObj = $("#diamond_carat_slider");
    var diamondCarat = $silderObj.attr("data-carat");
    var sliderW = parseInt($silderObj.css("width"));
    var bar2Right = sliderW - diamondCarat * (sliderW/4.5);
    $silderObj.children(".mask-slider").css("right",bar2Right);
    $silderObj.children(".bar2").css("right",bar2Right);

    // 切换图片 正面图 侧面图 艺术图
    $("#thumb_list .common-s-img").on("click",function(){
        var imgSrc = $(this).children('img').attr("src");
        $(this).addClass("active").siblings('li').removeClass("active");
        $("#diamond_show_img .common-img").fadeIn();
        $("#diamond_show_img .panoramic-img").fadeOut();
        $("#diamond_big_img").attr("src",imgSrc);
        $("#show_big_img").attr("src",imgSrc);
        
    });
    $("#thumb_list .panoramic-s-img").on("click", function () {
        $("#ok-loupe").hide();
        $(this).addClass("active").siblings('li').removeClass("active");
        $("#diamond_show_img .common-img").fadeOut();
        $("#diamond_show_img .panoramic-img").fadeIn();

    });
    // 全景图
    $("#panoramic_img").vc3dEye({
        imagePath: "../../../Public/img/panoramic/",
        totalImages: 51,
        imageExtension: "png"
    });
    // 放大镜效果
    $('#diamond_big_img').okzoom({
        width: 220,
        height: 220,
        round: true,
        background: "#fff",
        backgroundRepeat: "no-repeat",
        shadow: "0 0 8px #000",
        border: "1px solid #eee"
    });
   
    // 购物车数量加
    $(".icon-add").click(function () {
        var $obj = $("#diamond_num");
        if ($obj.val() == "" || undefined || null) {
            $obj.val(1);
        }
        $obj.val(parseInt($obj.val()) + 1);
    });
    // 数量减少
    $(".icon-reduce").click(function () {
        var $obj = $("#diamond_num");
        if ($obj.val() == "" || undefined || null) {
            $obj.val(1);
        }
        $obj.val(parseInt($obj.val()) - 1)
        if (parseInt($obj.val()) < 1) {
            $obj.val(1);
        }
    });
    // 修改输入框的数量
    $("#diamond_num").keyup(function () {
        var $obj = $("#diamond_num");
        if (parseInt($obj.val()) == "" || undefined || null || isNaN($obj.val())) {
            $obj.val(1);
        }
    });
    // tab切换栏
    $("#intro_btn button").on("click",function () {
        // 给当前元素添加active
        // 给当前这个元素的所有兄弟元素移除active
        $(this).addClass("active").siblings().removeClass("active");

        // 让下面的div的内容，根据上面的tab栏菜单显示
        var index = $(this).index();
        $("#intro_des_box>div").eq(index).addClass("selected").siblings("div").removeClass("selected");

    });
});